part of '../repository.dart';

class _CollectionListItemDtoFactory {
  const _CollectionListItemDtoFactory._internal();

  static const _instance = _CollectionListItemDtoFactory._internal();

  factory _CollectionListItemDtoFactory() {
    return _instance;
  }

  _CollectionListItemDto fromJson(Map<String, dynamic> json) {
    final type = json[_kCollectionListItemTypeKey] as String;

    switch (type) {
      case _kCollectionTypeValue:
        return _CollectionDto.fromJson(json);
      case _kCollectionFolderTypeValue:
        return _CollectionFolderDto.fromJson(json);
      default:
        throw UnimplementedError();
    }
  }

  _CollectionListItemDto fromEntity(CollectionListItem collectionListItem) {
    switch (collectionListItem) {
      case Collection():
        return _CollectionDto.fromEntity(collectionListItem);
      case CollectionFolder():
        return _CollectionFolderDto.fromEntity(collectionListItem);
    }
  }
}
